<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="my-card">
        <div slot="header" class="clearfix">
          <!-- 左侧表单 -->
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item style="float: right">
              <!-- 右侧 -->
              <el-button class="my-btn" style="padding: 3px 0" type="text"
              @click="$refs.addMenus.dialogVisible = true;$refs.addMenus.getmenus()">
                <i class="el-icon-edit"></i>
                添加
              </el-button>
            </el-form-item>


            <el-table
              :data="list"
              style="width: 100%;margin-bottom: 20px;"
              row-key="id"
              default-expand-all
              :tree-props="{children: 'childs'}">
              <el-table-column
              
                label="标题"
                width="200">
                <template slot-scope="scope">
                  <i v-if="!scope.row.pid"
                  class="el-icon-folder-opened"
                  style="font-size: 16px"></i>
                  <i v-if="scope.row.pid&&!scope.row.is_point"
                  class="el-icon-document"
                  style="font-size: 16px"></i>
                  <i v-if="scope.row.is_point"
                  class="el-icon-view"
                  style="font-size: 16px"></i>
                  {{scope.row.title}}
                </template>
              </el-table-column>
              <el-table-column
                prop="code"
                label="权限点代码"
                >
              </el-table-column>
              <el-table-column
                prop="address"
                label="操作"
                width="260"
                align="center">
                <template slot-scope="{ row }">
                  <el-button type="primary" @click="datamenus(row);$refs.dataMenus.getmenus()">修改</el-button>
                  <el-button type="danger" @click="delmenus(row.id)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form>
        </div>
      </el-card>

      <addMenus ref="addMenus" @update-list="getmenus"></addMenus>
      <dataMenus ref="dataMenus" @update-list="getmenus"></dataMenus>
    </div>
  </div>
</template>

<script>
import {getmenus,delmenus,getmenusid} from '@/api/menu'
import addMenus from './components/add-menus.vue'
import dataMenus from './components/data-menus.vue'
export default {
  name: "articles",
  components:{addMenus,dataMenus},
  data() {
    return {
      formInline: {
        user: "",
        region: "",
      },
      list:[]
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
    },
    async getmenus(){
      const res=await getmenus()
      const res1 = JSON.parse(
        JSON.stringify(res).replaceAll("points", "childs")
      );
      this.list=res1
      console.log(this.list);
    },
    async delmenus(res){
      await delmenus(res)
      this.$message.success('删除成功')
      this.getmenus()
    },
    datamenus(res){
      console.log(123);
      console.log(res);
      this.$refs.dataMenus.isShow = true;
      this.getmenusid(res)
    },
    async getmenusid(res){
      const data=await getmenusid(res)
      console.log(data);
      this.$refs.dataMenus.dataForm(data)
    }
  },
  created(){
    this.getmenus()
  }
};
</script>

<style lang="scss" scoped>
// [data-v-f70f99cc]
// [data-v-f70f99cc]
// my-card
.my-card[data-v-f70f99cc] .el-card__header {
  padding: 100px;
  border-bottom: 5px solid #ebeef5 !important;
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
}
</style>
<style>
.my-card .el-card__header {
  padding-bottom: 0px;
  border-bottom: 0px solid #ebeef5 !important;
}
.my-card .el-card__body {
  padding-top: 0px;
}
.my-card .el-form-item {
  margin: 10px 0;
}
.my-card .el-alert {
  margin: 8px 0 16px;
}
.my-card .el-table__header-wrapper {
  border-bottom: 2px solid #e8e8e8;
  background-color: #fafafa;
}
.my-card th {
  background-color: #fafafa !important;
}
.my-card .my-btn {
  width: 95px;
  height: 32px;
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
}
.my-card .my-shou {
  width: 56px;
  height: 32px;
  padding: 0;
  line-height: 0;
  margin-left: 10px;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
}
.my-card .my-cha {
  width: 56px;
  height: 32px;
  padding: 0;
  line-height: 0;
}
.my-card .el-input__inner {
  height: 32px;
}
.my-card .my-item-two {
  margin-left: 40px;
}


</style>